<?php
header('content-type:text/html;charset=utf-8');
try{
	$pdo = new PDO('mysql:host=localhost;dbname=exercise', 'root', 'root');
	$sql = 'select * from user';
	
	//prepare($sql)； 准备一条SQl语句。
	$stmt = $pdo->prepare($sql);
	//execute(); 执行一条预处理语句
	$res = $stmt->execute();

	/*
	if($res) {
		while ($row = $stmt->fetch(PDO::FETCH_OBJ)) {
			print_r($row);
			echo "<hr/>";
		}
	}
	*/
	$stmt->setFetchMode(PDO::FETCH_ASSOC);
	$rows  = $stmt->fetchAll();
	print_r($rows);
	echo "<hr />";
	
}catch(PDOException $e) {
	echo $e->getMessage();
}
?>